var BlogPostBiz = {
		initialize : function(){
			
			$('#logout_btn').unbind('click').bind('click', function(){
				COMMAJAX.common_ajax({
					url : "/mind/home/logoutcheck.do",
					callback_fnc : function(){
						window.setTimeout('location.reload()', 1000);
					}
				});
			});
			
			// Get today's current date.
			var now = new Date();
			// Array list of days.
			var days = new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
			// Array list of months.
			var months = new Array('January','February','March','April','May','June','July','August','September','October','November','December');
			// Calculate the number of the current day in the week.
			// Calculate the number of the current day in the week.
			var date = ((now.getDate()<10) ? "0" : "")+ now.getDate();
			// Calculate four digit year.
			function fourdigits(number){
			    return (number < 1000) ? number + 1900 : number;
			                                }
			// Join it all together
			var today = days[now.getDay()] + ", " +
			        months[now.getMonth()] + " " +
			        date + ", " +
			        (fourdigits(now.getYear())) ;
			
			$('#datePost').append(today);
			
			// Log-In Check
			$('#submit_func').on("click" ,function(){
				$('#txt_regDate').val(today);
				
				paramData = {
					PARENT_BLOG_NO : $('#parent_blog_no').val(),
					REPLY_USER_NAME : $('#lbl_regName').val(),
					REPLY_USER_DATE : $('#txt_regDate').val(),
					REPLY_CONTENT : $('#message').val(),
				};
				
				COMMAJAX.common_ajax({
					url : "/mind/join/insertBlogComment.do"
						,data : paramData
						,callback_fnc :  function(data){
							
							var tag = '';
								tag += '<li class="comment">';
								tag += '<h6>';
								tag += '<span class="meta"><strong> ' + $('#lbl_regName').val() + '</strong> on ' + today + '</span>';
								tag += '</h6>';
								tag += '<p>' + data.rows.REPLY_CONTENT + '</p>';
							    tag += '</li>';
						
							if($('.comments ol').length == 0 ){
								$('.comments').append(tag);
							}else{
								$('.comments ol:last').after(tag);
							}
							
						$('#message').val("");
					}
				});
			});
			
			$('#btn_delete').on('click', function(){
				
				var paramData  ={
						BLOG_NO : $('#blog_no').val()
				};
				
				COMMAJAX.common_ajax({
					url : "/mind/join/deleteBlogDetail.do"
						,data : paramData
						,callback_fnc :  function(data){
							alert("삭제되었습니다.!!")
							
							location.href = '/views/blog.do';
					}
				});
			});
			
			$('#btn_modify').on('click', function(){
				
				var contents = $('.entry').text();
				
				$('#btn_modify').replaceWith('<a id="btn_modify_complete" >수정완료</a>');
				$('div.entry').replaceWith('<div class="entry"><textarea id="contents" ></textarea></div>');
				
				$('#contents').val($.trim(contents));
				
				$('#btn_modify_complete').on('click', function(){
					
					var paramData  ={
							BLOG_NO : $('#blog_no').val(),
							CONTENT : $('#contents').val()
					};
					
					COMMAJAX.common_ajax({
						url : "/mind/join/updateBlogDetail.do"
							,data : paramData
							,callback_fnc :  function(data){
								
								alert("수정완료되었습니다. !!")
								
								location.reload();
						}
					});
				});
			});
			
			$('#btn_favorite').on('click', function(){
				
				var paramData = {
						BLOG_NO : $('#blog_no').val(),
						USER_NAME : $('#lbl_regName').val()
					};
				
				$('#btn_favorite').replaceWith('');
				
				COMMAJAX.common_ajax({
					url : "/mind/insertFavorite.do"
						,data : paramData
						,callback_fnc :  function(data){
							
							if(data){
								if(data.rows.length != 0){
									var cnt = data.rows.length;
									var str = "";
									for(var i = 0 ; i < cnt ; i++){
										str += data.rows[i]["USER_NAME"] + ',';
									}
									
									$('#lbl_content').text(str.substring(0, str.lastIndexOf(',')) + "가 이글을 좋아합니다. ");
								}
							}
					}
				});

				

				
			});
			
			
			

		}
}


!function($){
	BlogPostBiz.initialize();	
}(jQuery);